<template>
  <div class="login-container">
    <!-- 登录类型切换 -->
    <div class="login-type-tabs">
      <button :class="{ active: loginType === 'system' }"
@click="loginType = 'system'">
        系统用户
      </button>
      <button :class="{ active: loginType === 'client' }"
@click="loginType = 'client'">
        客户
      </button>
    </div>

    <!-- 系统用户登录表单 -->
    <div v-if="loginType === 'system'"
class="login-form">
      <h2>系统用户登录</h2>
      <div class="form-group">
        <label>账号</label>
        <input
v-model="system.username" type="text" placeholder="请输入账号" />
      </div>
      <div class="form-group">
        <label>密码</label>
        <input
v-model="system.password" type="password" placeholder="请输入密码" />
      </div>
      <div class="form-options">
        <label>
          <input
v-model="system.remember" type="checkbox" />
          记住密码
        </label>
        <a href="#"
class="forgot-password">忘记密码？</a>
      </div>
      <button
class="login-btn" @click="handleSystemLogin">登录</button>
      <div class="wechat-login">
        <p>或使用微信登录</p>
        <button class="wechat-btn"
@click="handleWechatLogin">
          <img
src="@/assets/wechat-icon.png" alt="微信登录" />
        </button>
      </div>
    </div>

    <!-- 客户登录表单 -->
    <div v-if="loginType === 'client'"
class="login-form">
      <h2>客户登录</h2>
      <div class="login-methods">
        <button :class="{ active: clientMethod === 'phone' }"
@click="clientMethod = 'phone'">
          手机验证码
        </button>
        <button :class="{ active: clientMethod === 'account' }"
@click="clientMethod = 'account'">
          账号密码
        </button>
      </div>

      <div v-if="clientMethod === 'phone'"
class="form-group">
        <label>手机号</label>
        <div class="phone-input">
          <input
v-model="client.phone" type="tel" placeholder="请输入手机号" />
          <button class="sms-btn"
:disabled="smsCountdown > 0" @click="sendSmsCode">
            {{ smsCountdown > 0 ? `${smsCountdown}s后重试` : '获取验证码' }}
          </button>
        </div>
      </div>
      <div v-if="clientMethod === 'phone'"
class="form-group">
        <label>验证码</label>
        <input
v-model="client.code" type="text" placeholder="请输入验证码" />
      </div>

      <div v-if="clientMethod === 'account'"
class="form-group">
        <label>账号</label>
        <input
v-model="client.username" type="text" placeholder="请输入账号" />
      </div>
      <div v-if="clientMethod === 'account'"
class="form-group">
        <label>密码</label>
        <input
v-model="client.password" type="password" placeholder="请输入密码" />
      </div>

      <div class="form-options">
        <a href="#"
class="forgot-password">忘记密码？</a>
      </div>
      <button class="login-btn"
@click="handleClientLogin">
        {{ clientMethod === 'phone' ? '验证码登录' : '账号登录' }}
      </button>
      <div class="wechat-login">
        <p>或使用微信登录</p>
        <button class="wechat-btn"
@click="handleWechatLogin">
          <img
src="@/assets/wechat-icon.png" alt="微信登录" />
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { ref } from 'vue'

  const loginType = ref('system') // system/client
  const clientMethod = ref('phone') // phone/account
  const smsCountdown = ref(0)

  const system = ref({
    username: '',
    password: '',
    remember: false,
  })

  const client = ref({
    phone: '',
    code: '',
    username: '',
    password: '',
  })

  const sendSmsCode = () => {
    smsCountdown.value = 60
    const timer = setInterval(() => {
      smsCountdown.value--
      if (smsCountdown.value <= 0) {
        clearInterval(timer)
      }
    }, 1000)
  }

  const handleSystemLogin = () => {
    console.log('系统用户登录:', system.value)
  }

  const handleClientLogin = () => {
    console.log('客户登录:', client.value)
  }

  const handleWechatLogin = () => {
    console.log('微信登录')
  }
</script>

<style scoped lang="scss">
  .login-container {
    padding: 20px;
    max-width: 100%;
    margin: 0 auto;

    .login-type-tabs {
      display: flex;
      margin-bottom: 30px;
      border-bottom: 1px solid #eee;

      button {
        flex: 1;
        padding: 12px;
        background: none;
        border: none;
        font-size: 16px;
        color: #666;
        position: relative;

        &.active {
          color: #1989fa;
          font-weight: bold;

          &::after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 20%;
            right: 20%;
            height: 3px;
            background: #1989fa;
            border-radius: 3px;
          }
        }
      }
    }

    .login-form {
      h2 {
        text-align: center;
        margin-bottom: 30px;
        color: #333;
      }

      .login-methods {
        display: flex;
        margin-bottom: 20px;

        button {
          flex: 1;
          padding: 10px;
          background: none;
          border: none;
          font-size: 14px;
          color: #666;

          &.active {
            color: #1989fa;
            font-weight: bold;
          }
        }
      }

      .form-group {
        margin-bottom: 20px;

        label {
          display: block;
          margin-bottom: 8px;
          font-size: 14px;
          color: #666;
        }

        input {
          width: 100%;
          padding: 12px 15px;
          border: 1px solid #ddd;
          border-radius: 4px;
          font-size: 15px;

          &:focus {
            border-color: #1989fa;
          }
        }

        .phone-input {
          display: flex;
          gap: 10px;

          input {
            flex: 1;
          }

          .sms-btn {
            width: 120px;
            background: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 4px;
            color: #1989fa;

            &:disabled {
              color: #999;
            }
          }
        }
      }

      .form-options {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        font-size: 14px;

        .forgot-password {
          color: #1989fa;
          text-decoration: none;
        }
      }

      .login-btn {
        width: 100%;
        padding: 12px;
        background: #1989fa;
        color: white;
        border: none;
        border-radius: 4px;
        font-size: 16px;
        margin-bottom: 20px;
      }

      .wechat-login {
        text-align: center;

        p {
          color: #999;
          margin-bottom: 15px;
          position: relative;

          &::before,
          &::after {
            content: '';
            position: absolute;
            top: 50%;
            width: 30%;
            height: 1px;
            background: #eee;
          }

          &::before {
            left: 0;
          }

          &::after {
            right: 0;
          }
        }

        .wechat-btn {
          background: none;
          border: none;

          img {
            width: 40px;
            height: 40px;
          }
        }
      }
    }
  }
</style>
